<%--  ilogin. jsp --%>
<%@page contentType="text/html;charset=UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
    <title>Web Baesd Intelligent Tutoring System in Sudoku for Logic Training</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <%-- CSS is get from http://www.freelayouts.com/ --%>
    <link rel="stylesheet" type="text/css" href="css/default.css" title="default"/>
</head>

<body>
    <jsp:include page='header.jsp'/>
    <%@ include file='DatabaseSetup.jsp'%>


    <div class="article_body">

        <p>
            <h3>If you are not our member yet, press <a href="registration.jsp">here</a> for registration!<br/>
            如果你不是會員, 按<a href="registration.jsp">此處</a>註冊!<br/></h3>
        </p>

        <form name="LoginForm" method="post">
            <table name="LoginTable">
                <tr>
                    <td>Email Address 電子郵件地址</td>
                    <td><input type="text" name="Email" ></td>
                </tr>
                <tr>
                    <td>Password 密碼</td>
                    <td><input type="password" name="Password"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" class="submit" name="submit" value="LogIn"></td>
                </tr>
            </table>
        </form>
        <p><h2>

    <%
        String email=request.getParameter("Email");
        String password=request.getParameter("Password");

        ResultSet rs = null;

        try{
            rs=stmt.executeQuery("select userID, email, password, langmode from userinfo");
            while(rs.next()){

                String user = rs.getString(1);
                String mail=rs.getString(2);
                String pass=rs.getString(3);
                String langmode = rs.getString(4);

                if(email.equals(mail) && password.equals(pass)){
                    session.setAttribute("email", email);
                    session.setAttribute("user", user);
                    session.setAttribute("langMode", langmode);
                    out.println("Login Success! You will be redirected to index page after 3 second.if not, press<a href=\"index.jsp\">here</a><br/>");
                    out.println("己登入!3秒後進入主頁面.如沒有，請按<a href=\"index.jsp\">此</a><br/>");
                    response.setHeader("Refresh", "3; URL=" + "http://144.214.121.25:8080/SudokuITSWebsite/index.jsp");
                }/*else{
                    out.println("Login Failed,Please try again.<br/>");
                    out.println("登入錯誤, 請再試一次.<br/>");
                }*/
            }
        }catch(Exception e){}

        rs.close();
        con.close();
        stmt.close();
    %>
    
        </h2></p>
     </div>

    <jsp:include page='footer.jsp'/>
</body>
</html>
